java中怎么把"a+b-c"拆分成单个字符的数组呢?

来源:百度知道 编辑:UC知道 时间:2024/05/12 20:32:04

String str="abcdefg";
char a[];
a=str.toCharArray();

也可以用方法:
getChars
public void getChars(int srcBegin,
int srcEnd,
char dst[],
int dstBegin)
从该字符串中拷贝字符到目的字符数组中。
第一个要复制的字符在索引 srcBegin 处; 最后一个要复制的字符在索引 srcEnd-1 处(因此要复制的字符总数就是 srcEnd-srcBegin) 。要复制到 dst 子数组的字符开始于索引 dstBegin ,结束于索引:
dstbegin + (srcEnd-srcBegin) - 1
参数:
srcBegin - 要复制的字符串中第一个字符的索引。
srcEnd - 要复制的字符串中最后一个字符的索引。
dst - 目标数组。
dstBegin - 目标数组中的开始偏移量。

String str="abcdefg";
char a[];
str.getChars(0,str.length(),a,0);

String str = "a+b-c";
char[] c = str.toCharArray();